﻿using System;
using System.Web;

namespace DBFile.Core.Web
{
	/// <summary>
	/// This is the abstract class used to tie in the base functionality of an IHttpModule.
	/// </summary>
	public abstract class BaseHttpModule : IHttpModule
	{
		#region IHttpModule Members

		/// <summary>
		/// This method wires the event handler up to the correcet event
		/// </summary>
		/// <param name="app">Current HttpApplication</param>
		public void Init(HttpApplication app)
		{
			app.BeginRequest += new EventHandler(this.BaseHttpModuleBeginRequest);
		}

		/// <summary>
		/// Used to dispose any objects that might need cleaned up.  Currently not implemented.
		/// </summary>
		public void Dispose()
		{ }

		#endregion

		#region Methods
		/// <summary>
		/// Eventhandler used to tie the loading of the file to the logic we implement.
		/// </summary>
		/// <param name="sender">Current HttpApplication</param>
		/// <param name="e">Eventargs coming in</param>
		internal void BaseHttpModuleBeginRequest(object sender, EventArgs e)
		{
			HttpApplication app = (HttpApplication)sender;
			Open(app.Request.Path, app);
		}
		#endregion

		#region Abstract Methods
		/// <summary>
		/// Method to override in the concrete class.  Currently only have GetFileHttpModule
		/// </summary>
		/// <param name="requestedPath">url typed in the browser</param>
		/// <param name="app">Current HttpApplication</param>
		protected abstract void Open(string requestedPath, HttpApplication app);
		#endregion

	}
}
